unit LT_Plugin;

interface
uses
  Dialogs,Classes,Sysutils,
  PluginElems,LT_Tasks,LT_Calendar,LT_Task,Observable;

type
  TFOnAllDataLoaded = procedure of object;
  TLT_Plugin=class(TObservable)
    private
      FTaskChanged:TNotifyEvent;
      FAllDataLoaded:TNotifyEvent;
      FAllDataUnloaded:TNotifyEvent;
      FExecuteMainCommand:TNotifyEvent;
      FTasks:TLT_Tasks;
      FCalendar:TLT_Calendar;

    protected

    procedure startChanges();
    procedure endChanches();
    public
    OnTaskMenuCommandExecute:TNotifyEvent;
    constructor Create();
    //exports
    function GetMainCommandName():PWideChar;virtual;abstract;
    procedure TaskChanged(uid:TLT_UID);virtual;

    //====
    procedure testAPI(var list:TStrings);
    procedure AllDataLoaded();
    procedure AllDataUnloaded();
    procedure ExecuteMainCommand();
    procedure TaskMenuCommandExecute(uid:TLT_UID);

    property Calendar:TLT_Calendar read FCalendar;


    property OnExecuteMainCommand:TNotifyEvent read FExecuteMainCommand write FExecuteMainCommand;
    property OnAllDataUnloaded:TNotifyEvent read FAllDataUnloaded write FAllDataUnloaded;
    property OnAllDataLoaded:TNotifyEvent read FAllDataLoaded write FAllDataLoaded;
    property OnTaskChanged:TNotifyEvent read FTaskChanged write FTaskChanged;
    property Tasks:TLT_Tasks read FTasks;
  end;

implementation

{ TLeaderTask }


procedure TLT_Plugin.AllDataLoaded;
begin
  if Assigned(OnAllDataLoaded) then OnAllDataLoaded(self);
end;

procedure TLT_Plugin.AllDataUnloaded;
begin
  if Assigned(OnAllDataUnLoaded) then OnAllDataUnLoaded(self);
end;

constructor TLT_Plugin.Create;
begin
  inherited;
  FTasks:=TLT_Tasks.Create();
  FCalendar:=TLT_Calendar.Create();
end;


procedure TLT_Plugin.endChanches;
begin
  AddinLT_ChangesEnd();
end;






procedure TLT_Plugin.ExecuteMainCommand;
begin
  if Assigned(OnExecuteMainCommand) then OnExecuteMainCommand(self);
end;

procedure TLT_Plugin.startChanges;
begin
  AddinLT_ChangesStart();
end;

procedure TLT_Plugin.TaskChanged(uid: TLT_UID);
begin
  if Assigned(OnTaskChanged) then OnTaskChanged(TLT_Task.Create(uid));
end;

procedure TLT_Plugin.TaskMenuCommandExecute(uid: TLT_UID);
begin
  if Assigned(OnTaskMenuCommandExecute) then OnTaskMenuCommandExecute(TObject(uid));
end;

procedure TLT_Plugin.testAPI(var list: TStrings);
begin
list.Add('======testAPI=====');
Tasks.testAPI(list);
Calendar.testAPI(list);
end;

end.
